package edu.uwm.universitydb.swing;

import java.util.List;

import edu.uwm.universitydb.model.Student;
import edu.uwm.universitydb.service.student.StudentService;

public class StudentTableModel extends DataTableModel {
	
	public StudentTableModel(StudentService service) {
		super(_colNames, _colTypes);
		_studentService = service;
		users = _studentService.getAllStudents();
	}
	

	public StudentService getService() {
		return _studentService;
	}
	
	@Override
	public int getRowCount() {
		return users.size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0:
			return users.get(row).getSsnNum();
		case 1:
			return users.get(row).getName();
		case 2:
			return users.get(row).getStrAge();
		case 3:
			return users.get(row).getProgram();
		case 4:
			return users.get(row).getDepartment().getDeptName();
		default:
			return "Error";
		}
	}
	
	private static final String[] _colNames = new String[] {"SSN","Name", "Age", "Degree", "Dept"};
	private static final Class<?>[] _colTypes = new Class<?>[] {String.class, String.class, String.class, String.class, String.class};
	
	private List<Student> users;
	private final StudentService _studentService;

	private static final long serialVersionUID = 7109350572697511477L;

	public void refreshData() {
		users = _studentService.getAllStudents();
	}

}
